# delimit ;  
set more 1 ;  

drop _all;
clear all;
capture log close;
set maxvar 32000;
set mem 1000m;

*global folder "C:\research";
*global folder "C:\Users\Ali\Documents";
*global folder "d:\Dropbox";
global folder "C:\Users\ebf26\Dropbox";
*global folder "/Users/charlesarapakis/Desktop";
*global folder "C:\Users\Jeremy\Dropbox";
*global folder "\\econ-san-fs\Home4\uctpkp0\SystemFolder\Windows7\Desktop";


         local saved  "$folder/hrs/merge/";
         local trackd "$folder\hrs\tracker\";
         local wave1d "$folder\hrs\wave1\";
         local wave2d "$folder\hrs\wave2\";
         local wave3d "$folder\hrs\wave3\";
         local wave4d "$folder\hrs\wave4\";
         local wave5d "$folder\hrs\wave5\";
		 local wave6d "$folder\hrs\wave6\";
         local wave7d "$folder\hrs\wave7\";
         local wave8d "$folder\hrs\wave8\";
		 local wave9d "$folder\hrs\wave9\";
		 local wave10d "$folder\hrs\wave10\";
		 local wave11d "$folder\hrs\wave11\";
		 local wave12d "$folder\hrs\wave12\";
		 local wave13d "$folder\hrs\wave13\";
		 local wave14d "$folder\hrs\wave14\";
		 local wave15d "$folder\hrs\wave15\";

         local aheadw1 "$folder\hrs\aheadw1\";
         local aheadw2 "$folder\hrs\aheadw2\";


log using `merge'insuranceimpute.log, replace ;
use `saved'merge5;
gen long hhidpn=HHID;
replace hhidpn=hhidpn*1000+PN;
rename hhidpn indnum;


******************************************************;
* code health insurance data**************************;
* many of the variables are currently properly coded;
* epins = employer provided insurance;
* inssp = spousal insurance;
* inspriv = privately purchased health insurance;
*******************************************************;
* recode health insurance variables below ;
gen insnone=.;
replace insnone=1 if epins==0 & insgov==0 & inssp==0 & inspriv==0 & medcare==0;
replace insnone=0 if epins==1|(insgov==1|insgov==2)|inssp==1|inspriv==1|medcare==1;


* now spouses;
gen _insnone=.;
replace _insnone=1 if _epins==0 & _insgov==0 & _inssp==0 & _inspriv==0 & _medcare==0;
replace _insnone=0 if _epins==1|(_insgov==1|_insgov==2)|_inssp==1|_inspriv==1|_medcare==1 ;

compress;

save `merge'insuranceimpute, replace;
drop _all;
log close ;
